package topin.facecat.FaceCat.Product.UI

import facecat.topin.btn.FCButton
import facecat.topin.core.FCColor
import facecat.topin.core.FCPaint
import facecat.topin.core.FCPoint
import facecat.topin.core.FCRect


class ArrowButtonM : FCButton() {
    /**
     * 获取或设置箭头类型
     */
    var arrowType = 0

    /**
     * 重绘背景
     * @param paint 绘图对象
     * @param clipRect 裁剪区域
     */
    override fun onPaintBackground(paint: FCPaint, clipRect: FCRect) {
        val text = text
        val width = width
        val height = height
        val mw = width / 2
        val mh = height / 2 + 2
        val drawRect = FCRect(0, 0, width, height)
        if (arrowType > 0) {
            val points = arrayOfNulls<FCPoint>(3)
            val ts = Math.min(mw, mh) / 2 + 2
            when (arrowType) {
                1 -> {
                    points[0] = FCPoint(mw - ts, mh)
                    points[1] = FCPoint(mw + ts, mh - ts)
                    points[2] = FCPoint(mw + ts, mh + ts)
                }
                2 -> {
                    points[0] = FCPoint(mw + ts, mh)
                    points[1] = FCPoint(mw - ts, mh - ts)
                    points[2] = FCPoint(mw - ts, mh + ts)
                }
                3 -> {
                    points[0] = FCPoint(mw, mh - ts)
                    points[1] = FCPoint(mw - ts, mh + ts)
                    points[2] = FCPoint(mw + ts, mh + ts)
                }
                4 -> {
                    points[0] = FCPoint(mw, mh + ts - 3)
                    points[1] = FCPoint(mw - ts + 3, mh - ts + 3)
                    points[2] = FCPoint(mw + ts - 3, mh - ts + 3)
                }
            }
            paint.fillPolygon(textColor, points)
        }
    }

    /**
     * 创建透明按钮
     */
    init {
        borderColor = FCColor.None
    }
}